#!/bin/sh

WATCH_DIR=/data/www/mz/mztest/socket/log
WATCH_FILE=$WATCH_DIR/.restart
PFILE=/var/tmp/monapp_mz_test.pid

echo "monitor start..."
echo $$ > $PFILE

while :
do

	TIMESTAMP=0
	PID=0
	I=0

	for line in `cat $WATCH_FILE | tr -d '\\r'`
	do
		if [ $I -eq 0 ]
		then
			PID=$line
		fi
		if [ $I -eq 1 ]
		then
			TIMESTAMP=$line
		fi

		I=$(($I+1))
	done
	
	if [ $PID -gt 0 ]
	then
		## Execute commands
		kill -9 $PID
		echo "execute..."
		> $WATCH_FILE
	fi
	sleep 1
done

